#region License
/*
MIT License
Copyright © 2006 The Mono.Xna Team

All rights reserved.

Authors
 * Alan McGovern

Adapted for Vortex2D.NET
 * Alex Khomich

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#endregion License

using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Vortex.Drawing {

	/// <summary>
	/// Vector2 is component (X,Y) vector class which describes location of point or vector in 2D space
	/// </summary>
	[Serializable]
	[StructLayout(LayoutKind.Sequential)]
	public struct Vector2 : IEquatable<Vector2> {
		#region Constants

		///<summary>Zero vector, both of components are equal 0</summary>
		public static readonly Vector2 Zero = new Vector2(0f, 0f);
		///<summary>Unit vector, both of components are equal 1</summary>
		public static readonly Vector2 Unit = new Vector2(1f, 1f);
		///<summary>Double unit vector, both of components are equal 2</summary>
		public static readonly Vector2 DoubleUnit = new Vector2(2f, 2f);
		///<summary>UnitX vector, X component is 1, Y = 0</summary>
		public static readonly Vector2 UnitX = new Vector2(1f, 0f);
		///<summary>UnitY vector, Y component is 1, X = 0</summary>
		public static readonly Vector2 UnitY = new Vector2(0f, 1f);

		///<summary>Left vector (-1, 0)</summary>
		public static readonly Vector2 Left = new Vector2(-1f, 0f);
		///<summary>Left vector (1, 0)</summary>
		public static readonly Vector2 Right = new Vector2(1f, 0f);
		///<summary>Left vector (0, 1)</summary>
		public static readonly Vector2 Down = new Vector2(0f, 1f);
		///<summary>Left vector (0, -1)</summary>
		public static readonly Vector2 Up = new Vector2(0f, -1f);

		#endregion

		#region Public Fields

		///<summary>X component of vector</summary>
		[System.Xml.Serialization.XmlAttribute]
		public float X;
		///<summary>Y component of vector</summary>
		[System.Xml.Serialization.XmlAttribute]
		public float Y;

		#endregion


		#region Properties

		/// <summary>
		/// Gets the magnitude of vector.
		/// </summary>
		/// <value>The magnitude of vector.</value>
		public float Magnitude {
			get { return Length(); }
		}

		/// <summary>
		/// Gets the squared magnitude of vector.
		/// </summary>
		/// <value>The squared magnitude of vector.</value>
		public float SquaredMagnitude {
			get { return LengthSquared(); }
		}

		/// <summary>
		/// Gets the negative vector.
		/// </summary>
		/// <value>The negative vector.</value>
		public Vector2 Negative {
			get { return new Vector2(-X, -Y); }
		}

		/// <summary>
		/// Gets the absolute vector.
		/// </summary>
		/// <value>The absolute vector.</value>
		public Vector2 Absolute {
			get { return new Vector2(Math.Abs(X), Math.Abs(Y));  }
		}


		/// <summary>
		/// Gets the half of vector.
		/// </summary>
		/// <value>The half of vector.</value>
		public Vector2 Half {
			get { return new Vector2(X * 0.5f, Y * 0.5f); }
		}

		/// <summary>
		/// Gets the inverted vector (1/X,Y).
		/// </summary>
		/// <value>The inverted vector.</value>
		public Vector2 Inverted {
			get {
				return new Vector2(1 / X, 1 / Y);
			}
		}

		/// <summary>
		/// Gets the normalized vector copy.
		/// </summary>
		/// <value>The normalized vector.</value>
		public Vector2 Normalized {
			get {
				float factor = 1 / Length();
				return new Vector2(X * factor, Y * factor);
			}
		}

		/// <summary>
		/// Gets the floored vector.
		/// </summary>
		/// <value>The floored vector.</value>
		public Vector2 Floored {
			get { return Floor(); }
		}

		/// <summary>
		/// Gets the ceiling vector.
		/// </summary>
		/// <value>The ceiling vector.</value>
		public Vector2 Ceiled {
			get { return Ceiling(); }
		}

		/// <summary>
		/// Gets the rounded vector.
		/// </summary>
		/// <value>The rounded vector.</value>
		public Vector2 Rounded {
			get { return Round(); }
		}

		/// <summary>
		/// Gets a value indicating whether this instance is empty (both X and Y are 0).
		/// </summary>
		/// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
		public bool IsEmpty {
			get { return X == 0f && Y == 0f; }
		}

		#endregion


		#region Constructors

		/// <summary>
		/// Constructor for standard 2D vector.
		/// </summary>
		/// <param name="x">
		/// A <see cref="System.Single"/>
		/// </param>
		/// <param name="y">
		/// A <see cref="System.Single"/>
		/// </param>
		public Vector2(float x, float y) {
			this.X = x;
			this.Y = y;
		}

		/// <summary>
		/// Constructor for "square" vector.
		/// </summary>
		/// <param name="value">
		/// A <see cref="System.Single"/>
		/// </param>
		public Vector2(float value) {
			this.X = value;
			this.Y = value;
		}

		/// <summary>
		/// Initializes a vector <see cref="Vector2"/> struct from <see cref="System.Drawing.Point"/>.
		/// </summary>
		/// <param name="value">A <see cref="System.Drawing.Point"/></param>
		public Vector2(Point value) {
			this.X = value.X;
			this.Y = value.Y;
		}

		/// <summary>
		/// Initializes a vector <see cref="Vector2"/> struct from <see cref="System.Drawing.PointF"/>.
		/// </summary>
		/// <param name="value">A <see cref="System.Drawing.PointF"/></param>
		public Vector2(PointF value) {
			this.X = value.X;
			this.Y = value.Y;
		}

		/// <summary>
		/// Initializes a vector <see cref="Vector2"/> struct from <see cref="System.Drawing.Size"/>.
		/// </summary>
		/// <param name="value">A <see cref="System.Drawing.Size"/></param>
		public Vector2(Size value) {
			this.X = value.Width;
			this.Y = value.Height;
		}

		/// <summary>
		/// Initializes a vector <see cref="Vector2"/> struct from <see cref="System.Drawing.SizeF"/>.
		/// </summary>
		/// <param name="value">A <see cref="System.Drawing.SizeF"/></param>
		public Vector2(SizeF value) {
			this.X = value.Width;
			this.Y = value.Height;
		}

		#endregion

		#region ToXXXX Methods

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString() {
			return string.Format("{{{0},{1}}}", X, Y);
		}

		/// <summary>
		/// Returns a <see cref="System.Drawing.Point"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.Drawing.Point"/> that represents this instance.
		/// </returns>
		public Point ToPoint() {
			return new Point((int)X, (int)Y);
		}

		/// <summary>
		/// Returns a <see cref="System.Drawing.PointF"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.Drawing.PointF"/> that represents this instance.
		/// </returns>
		public PointF ToPointF() {
			return new PointF(X, Y);
		}

		/// <summary>
		/// Returns a <see cref="System.Drawing.Size"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.Drawing.Size"/> that represents this instance.
		/// </returns>
		public Size ToSize() {
			return new Size((int)X, (int)Y);
		}

		/// <summary>
		/// Returns a <see cref="System.Drawing.SizeF"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.Drawing.SizeF"/> that represents this instance.
		/// </returns>
		public SizeF ToSizeF() {
			return new SizeF(X, Y);
		}


		/// <summary>
		/// Returns a <see cref="Vortex.Drawing.Vector3"/> based on this Vector2 instance and Z = 0.
		/// </summary>
		/// <returns>
		/// A <see cref="Vortex.Drawing.Vector3"/> based on this Vector2.
		/// </returns>
		public Vector3 ToVector3() {
			return new Vector3(X, Y, 0);
		}

		/// <summary>
		/// Returns a <see cref="Vortex.Drawing.Vector3"/> based on this Vector2 and z-value specified.
		/// </summary>
		/// <param name="z">The z for Vector3</param>
		/// <returns>A <see cref="Vortex.Drawing.Vector3"/> based on this Vector2.</returns>
		public Vector3 ToVector3(float z) {
			return new Vector3(X, Y, z);
		}

		#endregion

		#region Vortex2D.NET Public Methods

		/// <summary>
		/// Rounds the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="result">The result.</param>
		public static void Round(ref Vector2 value, out Vector2 result) {
			result.X = MathHelper.Round(value.X);
			result.Y = MathHelper.Round(value.Y);
		}

		/// <summary>
		/// Rounds the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns>The result.</returns>
		public static Vector2 Round(Vector2 value) {
			Round(ref value, out value);
			return value;
		}

		/// <summary>
		/// Rounds this instance.
		/// </summary>
		/// <returns>The result.</returns>
		public Vector2 Round() {
			Vector2 result;
			Round(ref this, out result);
			return result;
		}

		/// <summary>
		/// Floors the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="result">The result.</param>
		public static void Floor(ref Vector2 value, out Vector2 result) {
			result.X = MathHelper.Floor(value.X);
			result.Y = MathHelper.Floor(value.Y);
		}

		/// <summary>
		/// Floors the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns>The result.</returns>
		public static Vector2 Floor(Vector2 value) {
			Floor(ref value, out value);
			return value;
		}

		/// <summary>
		/// Floors this instance.
		/// </summary>
		/// <returns>The result.</returns>
		public Vector2 Floor() {
			Vector2 result;
			Floor(ref this, out result);
			return result;
		}

		/// <summary>
		/// Ceilings the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="result">The result.</param>
		public static void Ceiling(ref Vector2 value, out Vector2 result) {
			result.X = MathHelper.Ceiling(value.X);
			result.Y = MathHelper.Ceiling(value.Y);
		}

		/// <summary>
		/// Ceilings the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns>The result.</returns>
		public static Vector2 Ceiling(Vector2 value) {
			Ceiling(ref value, out value);
			return value;
		}

		/// <summary>
		/// Ceilings this instance.
		/// </summary>
		/// <returns>The result.</returns>
		public Vector2 Ceiling() {
			Vector2 result;
			Ceiling(ref this, out result);
			return result;
		}

		#endregion

		#region Arithmetic Operations

		public Vector2 Add(Vector2 value) {
			value.X += X;
			value.Y += Y;
			return value;
		}

		public static Vector2 Add(Vector2 value1, Vector2 value2) {
			value1.X += value2.X;
			value1.Y += value2.Y;
			return value1;
		}

		public static void Add(ref Vector2 value1, ref Vector2 value2, out Vector2 result) {
			result.X = value1.X + value2.X;
			result.Y = value1.Y + value2.Y;
		}

		public Vector2 Add(float value) {
			return new Vector2(X + value, Y + value);
		}

		public static Vector2 Add(Vector2 value1, float value2) {
			value1.X += value2;
			value1.Y += value2;
			return value1;
		}

		public static void Add(ref Vector2 value1, float value2, out Vector2 result) {
			result.X = value1.X + value2;
			result.Y = value1.Y + value2;
		}

		public Vector2 Subtract(Vector2 value) {
			value.X -= X;
			value.Y -= Y;
			return value;
		}

		public static Vector2 Subtract(Vector2 value1, Vector2 value2) {
			value1.X -= value2.X;
			value1.Y -= value2.Y;
			return value1;
		}

		public static void Subtract(ref Vector2 value1, ref Vector2 value2, out Vector2 result) {
			result.X = value1.X - value2.X;
			result.Y = value1.Y - value2.Y;
		}

		public Vector2 Subtract(float value) {
			return new Vector2(X - value, Y - value);
		}

		public static Vector2 Subtract(Vector2 value1, float value2) {
			value1.X -= value2;
			value1.Y -= value2;
			return value1;
		}

		public static void Subtract(ref Vector2 value1, float value2, out Vector2 result) {
			result.X = value1.X - value2;
			result.Y = value1.Y - value2;
		}

		public Vector2 Multiply(Vector2 value) {
			value.X *= X;
			value.Y *= Y;
			return value;
		}

		public static Vector2 Multiply(Vector2 value1, Vector2 value2) {
			value1.X *= value2.X;
			value1.Y *= value2.Y;
			return value1;
		}

		public static void Multiply(ref Vector2 value1, ref Vector2 value2, out Vector2 result) {
			result.X = value1.X * value2.X;
			result.Y = value1.Y * value2.Y;
		}

		public Vector2 Multiply(float value) {
			return new Vector2(X * value, Y * value);
		}

		public static Vector2 Multiply(Vector2 value1, float value2) {
			value1.X *= value2;
			value1.Y *= value2;
			return value1;
		}

		public static void Multiply(ref Vector2 value1, float value2, out Vector2 result) {
			result.X = value1.X * value2;
			result.Y = value1.Y * value2;
		}

		public Vector2 Divide(Vector2 value) {
			value.X /= X;
			value.Y /= Y;
			return value;
		}

		public static Vector2 Divide(Vector2 value1, Vector2 value2) {
			value1.X /= value2.X;
			value1.Y /= value2.Y;
			return value1;
		}

		public static void Divide(ref Vector2 value1, ref Vector2 value2, out Vector2 result) {
			result.X = value1.X / value2.X;
			result.Y = value1.Y / value2.Y;
		}

		public Vector2 Divide(float value) {
			return new Vector2(X / value, Y / value);
		}

		public static Vector2 Divide(Vector2 value1, float value2) {
			value1.X /= value2;
			value1.Y /= value2;
			return value1;
		}

		public static void Divide(ref Vector2 value1, float value2, out Vector2 result) {
			result.X = value1.X / value2;
			result.Y = value1.Y / value2;
		}

		#endregion

		#region Public Methods

		public Vector2 Reflect(Vector2 normal) {
			Vector2 result;
			Reflect(ref this, ref normal, out result);
			return result;
		}

		public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result) {
			float dot = Dot(vector, normal);
			result.X = vector.X - ((2f * dot) * normal.X);
			result.Y = vector.Y - ((2f * dot) * normal.Y);
		}

		public static Vector2 Reflect(Vector2 vector, Vector2 normal) {
			Vector2 result;
			Reflect(ref vector, ref normal, out result);
			return result;
		}

		public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2) {
			return new Vector2(
				MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2),
				MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2));
		}

		public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result) {
			result = new Vector2(
				MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2),
				MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2));
		}

		public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount) {
			return new Vector2(
				MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount),
				MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount));
		}

		public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result) {
			result = new Vector2(
				MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount),
				MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount));
		}

		public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max) {
			return new Vector2(
				MathHelper.Clamp(value1.X, min.X, max.X),
				MathHelper.Clamp(value1.Y, min.Y, max.Y));
		}

		public static void Clamp(ref Vector2 value1, ref Vector2 min, ref Vector2 max, out Vector2 result) {
			result = new Vector2(
				MathHelper.Clamp(value1.X, min.X, max.X),
				MathHelper.Clamp(value1.Y, min.Y, max.Y));
		}

		public float Distance(Vector2 value) {
			float result;
			Distance(ref this, ref value, out result);
			return result;
		}

		public static float Distance(Vector2 value1, Vector2 value2) {
			float result;
			DistanceSquared(ref value1, ref value2, out result);
			return (float)Math.Sqrt(result);
		}

		public static void Distance(ref Vector2 value1, ref Vector2 value2, out float result) {
			DistanceSquared(ref value1, ref value2, out result);
			result = (float)Math.Sqrt(result);
		}

		public float DistanceSquared(Vector2 value) {
			float result;
			DistanceSquared(ref this, ref value, out result);
			return result;
		}

		public static float DistanceSquared(Vector2 value1, Vector2 value2) {
			float result;
			DistanceSquared(ref value1, ref value2, out result);
			return result;
		}

		public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result) {
			result = (value1.X - value2.X) * (value1.X - value2.X) + (value1.Y - value2.Y) * (value1.Y - value2.Y);
		}

		public float Dot(Vector2 value) {
			float result;
			Dot(ref this, ref value, out result);
			return result;
		}

		public static float Dot(Vector2 value1, Vector2 value2) {
			return value1.X * value2.X + value1.Y * value2.Y;
		}

		public static void Dot(ref Vector2 value1, ref Vector2 value2, out float result) {
			result = value1.X * value2.X + value1.Y * value2.Y;
		}

		public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount) {
			Vector2 result = new Vector2();
			Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
			return result;
		}

		public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result) {
			result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
			result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
		}

		public float Length() {
			return (float)Math.Sqrt(X * X + Y * Y);
		}

		public float LengthSquared() {
			return X * X + Y * Y;
		}

		public Vector2 Lerp(Vector2 value, float amount) {
			Lerp(ref this, ref value, amount, out value);
			return value;
		}

		public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount) {
			return new Vector2(
				MathHelper.Lerp(value1.X, value2.X, amount),
				MathHelper.Lerp(value1.Y, value2.Y, amount));
		}

		public static void Lerp(ref Vector2 value1, ref Vector2 value2, float amount, out Vector2 result) {
			result = new Vector2(
				MathHelper.Lerp(value1.X, value2.X, amount),
				MathHelper.Lerp(value1.Y, value2.Y, amount));
		}

		public Vector2 Max(Vector2 value) {
			Max(ref this, ref value, out value);
			return value;
		}

		public static Vector2 Max(Vector2 value1, Vector2 value2) {
			value1.X = Math.Max(value1.X, value2.X);
			value1.Y = Math.Max(value1.Y, value2.Y);
			return value1;
		}

		public static void Max(ref Vector2 value1, ref Vector2 value2, out Vector2 result) {
			result.X = Math.Max(value1.X, value2.X);
			result.Y = Math.Max(value1.Y, value2.Y);
		}

		public Vector2 Min(Vector2 value) {
			Min(ref this, ref value, out value);
			return value;
		}

		public static Vector2 Min(Vector2 value1, Vector2 value2) {
			value1.X = Math.Min(value1.X, value2.X);
			value1.Y = MathHelper.Min(value1.Y, value2.Y);
			return value1;
		}

		public static void Min(ref Vector2 value1, ref Vector2 value2, out Vector2 result) {
			result.X = Math.Min(value1.X, value2.X);
			result.Y = Math.Min(value1.Y, value2.Y);
		}

		public static Vector2 Negate(Vector2 value) {
			return new Vector2(-value.X, -value.Y);
		}

		public static void Negate(ref Vector2 value, out Vector2 result) {
			result.X = -value.X;
			result.Y = -value.Y;
		}

		public void Normalize() {
			Normalize(ref this, out this);
		}

		public static Vector2 Normalize(Vector2 value) {
			Normalize(ref value, out value);
			return value;
		}

		public static void Normalize(ref Vector2 value, out Vector2 result) {
			float factor = 1f / value.Length();
			result.X = value.X * factor;
			result.Y = value.Y * factor;
		}

		public bool CollinearTo(Vector2 vector) {
			return IsCollinear(ref this, ref vector);
		}

		public static bool IsCollinear(ref Vector2 value1, ref Vector2 value2) {
			return value1.X * value2.Y == value2.X * value1.Y;
		}

		public static Vector2 SmoothStep(Vector2 value1, Vector2 value2, float amount) {
			return new Vector2(
				MathHelper.SmoothStep(value1.X, value2.X, amount),
				MathHelper.SmoothStep(value1.Y, value2.Y, amount));
		}

		public static void SmoothStep(ref Vector2 value1, ref Vector2 value2, float amount, out Vector2 result) {
			result = new Vector2(
				MathHelper.SmoothStep(value1.X, value2.X, amount),
				MathHelper.SmoothStep(value1.Y, value2.Y, amount));
		}

		public static Vector2 Transform(Vector2 position, Matrix matrix) {
			Transform(ref position, ref matrix, out position);
			return position;
		}

		public static void Transform(ref Vector2 position, ref Matrix matrix, out Vector2 result) {
			result = new Vector2((position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41,
								 (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42);
		}

		public static Vector2 TransformNormal(Vector2 normal, Matrix matrix) {
			Vector2.TransformNormal(ref normal, ref matrix, out normal);
			return normal;
		}

		public static void TransformNormal(ref Vector2 normal, ref Matrix matrix, out Vector2 result) {
			result = new Vector2((normal.X * matrix.M11) + (normal.Y * matrix.M21),
								 (normal.X * matrix.M12) + (normal.Y * matrix.M22));
		}

		#endregion Public Methods


		#region Operators

		public static Vector2 operator -(Vector2 value) {
			value.X = -value.X;
			value.Y = -value.Y;
			return value;
		}


		public static bool operator ==(Vector2 value1, Vector2 value2) {
			return value1.X == value2.X && value1.Y == value2.Y;
		}


		public static bool operator !=(Vector2 value1, Vector2 value2) {
			return value1.X != value2.X || value1.Y != value2.Y;
		}


		public static Vector2 operator +(Vector2 value1, Vector2 value2) {
			value1.X += value2.X;
			value1.Y += value2.Y;
			return value1;
		}

		public static Vector2 operator +(Vector2 value1, float value2) {
			value1.X += value2;
			value1.Y += value2;
			return value1;
		}


		public static Vector2 operator -(Vector2 value1, Vector2 value2) {
			value1.X -= value2.X;
			value1.Y -= value2.Y;
			return value1;
		}

		public static Vector2 operator -(Vector2 value1, float value2) {
			value1.X -= value2;
			value1.Y -= value2;
			return value1;
		}

		public static Vector2 operator *(Vector2 value1, Vector2 value2) {
			value1.X *= value2.X;
			value1.Y *= value2.Y;
			return value1;
		}


		public static Vector2 operator *(Vector2 value, float scaleFactor) {
			value.X *= scaleFactor;
			value.Y *= scaleFactor;
			return value;
		}


		public static Vector2 operator *(float scaleFactor, Vector2 value) {
			value.X *= scaleFactor;
			value.Y *= scaleFactor;
			return value;
		}


		public static Vector2 operator /(Vector2 value1, Vector2 value2) {
			value1.X /= value2.X;
			value1.Y /= value2.Y;
			return value1;
		}

		public static Vector2 operator /(Vector2 value1, float divider) {
			float factor = 1 / divider;
			value1.X *= factor;
			value1.Y *= factor;
			return value1;
		}

		#endregion

		#region Implicit operators

		public static implicit operator Vector2(Point point) {
			return new Vector2(point);
		}

		public static implicit operator Vector2(PointF point) {
			return new Vector2(point);
		}

		public static implicit operator Vector2(Size size) {
			return new Vector2(size);
		}

		public static implicit operator Vector2(SizeF size) {
			return new Vector2(size);
		}

		public static implicit operator Point(Vector2 vector) {
			return vector.ToPoint();
		}

		public static implicit operator PointF(Vector2 vector) {
			return vector.ToPointF();
		}

		public static implicit operator Size(Vector2 vector) {
			return vector.ToSize();
		}

		public static implicit operator SizeF(Vector2 vector) {
			return vector.ToSizeF();
		}

		#endregion

		#region Object support methods

		/// <summary>
		/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
		/// </summary>
		/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
		/// <returns>
		/// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
		/// </returns>
		public override bool Equals(object obj) {
			return (obj is Vector2) ? this == ((Vector2)obj) : false;
		}

		/// <summary>
		/// Indicates whether the current object is equal to another object of the same type.
		/// </summary>
		/// <param name="other">An object to compare with this object.</param>
		/// <returns>
		/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
		/// </returns>
		public bool Equals(Vector2 other) {
			return this == other;
		}

		/// <summary>
		/// Returns a hash code for this instance.
		/// </summary>
		/// <returns>
		/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
		/// </returns>
		public override int GetHashCode() {
			return (int)(this.X + this.Y);
		}

		#endregion
	}
}
